<%@ page language="java" contentType="application/json; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" import="support.*, java.util.*, myclasses.*, java.sql.*, net.sf.json.JSONArray, net.sf.json.JSONObject"%>
    
<%response.setContentType("application/json");
JSONObject jobject = new JSONObject();
JSONArray ja = new JSONArray();

try {
	Class.forName("org.postgresql.Driver");
} catch(Exception e) {
	out.println("org.postgresql.Driver Exception. ");
}

try {
	String serverName = "localhost:5432";
    String mydatabase = "ThirdBase";
    String url = "jdbc:postgresql://" + serverName + "/" + mydatabase; 
    String username = "SweetAss";
    String password = "1234";
    Connection conn = DriverManager.getConnection(url, username, password);
    
	Statement stmt = conn.createStatement();

	ResultSet rset = stmt.executeQuery("SELECT location,name FROM university");
	
   	while(rset.next()) {
   		
   		JSONObject jo = new JSONObject();
   		jo.put("location", rset.getString(1));
   		jo.put("name", rset.getString(2));
   		ja.element(jo);
   	}
   	//jobject.put(ja);
   	
	out.println(ja);
	out.flush();
	
	rset.close();
	stmt.close();
	conn.close();

} catch(SQLException e) {
	e.printStackTrace();
	out.println("Connection exception.");
}
%>